<template>
  <div>
    <swiper :options="swiperOption" class="icons-swiper">
      <swiper-slide v-for="(page,index) of pages" :key="index">
        <div class="icons">
          <div class="icon" v-for="item of page" :key="item.id">
            <img class="icons-img" :src="item.iconsUrl">
            <div class="icons-desc">{{item.iconsDesc}}</div>
          </div>
        </div>
      </swiper-slide>
      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>

export default {
  name: 'HomeIcons',
  props: {
    iconsList: Array
  },
  data () {
    return {
      swiperOption: {
          pagination: {
            el: '.swiper-pagination'
          },
          autoplay: false
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      this.iconsList.forEach((item,index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  },
  methods: {

  }
}

</script>

<style lang="stylus" scoped>
  .icons
    padding-top: .5rem
    overflow: hidden
    display: flex
    flex-wrap: wrap
    width: 100%
    line-height: 1/2vm
    .icon
      flex: 0 0 25%
      display: flex
      flex-direction: column
      overflow: hidden
      .icons-img
        width: 4rem
        margin: 0 auto
      .icons-desc
        text-align: center

</style>





